#include "webtabbutton.h"
#include "ui_webtabbutton.h"
#include "cfg.h"

const int MIN_WIDTH = (5 * 24 + 100 + 2);
const int MIN_HEIGHT = (32);


WebTabButton::WebTabButton(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::WebTabButton)
{
    ui->setupUi(this);

    //
    m_tabWidget = nullptr;

    //
    init();
}

WebTabButton::~WebTabButton()
{
    delete ui;
}


void WebTabButton::init()
{
    connect(ui->btNew, &QToolButton::clicked, this, &WebTabButton::btNewClicked);
    connect(ui->btMenu, &QToolButton::clicked, this, &WebTabButton::btMenuClicked);
    connect(ui->btMin, &QToolButton::clicked, this, &WebTabButton::btMinClicked);
    connect(ui->btMax, &QToolButton::clicked, this, &WebTabButton::btMaxClicked);
    connect(ui->btClose, &QToolButton::clicked, this, &WebTabButton::btCloseClicked);

    ui->btMin->setVisible(false);
    ui->btMax->setVisible(false);
    ui->btClose->setVisible(false);
}

QWidget* WebTabButton::getNewWidget()
{
    return ui->btNew;
}

QWidget* WebTabButton::getTitleWidget()
{
    return ui->lbTitle;
}

QWidget* WebTabButton::getMenuWidget()
{
    return ui->btMenu;
}

QWidget* WebTabButton::getMinWidget()
{
    return ui->btMin;
}

QWidget* WebTabButton::getMaxWidget()
{
    return ui->btMax;
}

QWidget* WebTabButton::getCloseWidget()
{
    return ui->btClose;
}


QSize WebTabButton::sizeHint() const
{
    QSize sizeHint(MIN_WIDTH, MIN_HEIGHT);

    if (m_tabWidget != nullptr)
    {
        int iWidth = m_tabWidget->rect().width() - m_tabWidget->tabBar()->sizeHint().width();
        if (iWidth < MIN_WIDTH)
        {
            iWidth = MIN_WIDTH;
        }

        sizeHint.setWidth(iWidth);
    }

    return sizeHint;
}

